Converting directed weighted graph D
- The edge list for a directed weighted graph stores ordered triples (source, target, weight). For graph D, this gives us: (A,B,3), (B,C,2), (C,A,5), (A,A,1). The ordering matters—(A,B,3) is distinct from (B,A,3) which doesn't exist in this graph.
- The adjacency list for directed graphs stores only outgoing neighbors from each vertex. We can represent weights as dictionary mappings: A maps to {B:3, A:1}, B maps to {C:2}, and C maps to {A:5}. No symmetry is enforced since edges are directional.
- The adjacency matrix for weighted graphs uses the actual weights instead of just 1s and 0s. Entry adj[i,j] contains the weight of edge i→j, or 0 if no edge exists. The matrix is not symmetric for directed graphs—adj[A,B]=3 but adj[B,A]=0.
- Note how the self-loop A→A appears in all three representations: as tuple (A,A,1) in the edge list, as A:1 in A's neighbor dictionary, and as value 1 on the diagonal at position adj[A,A] in the matrix. This demonstrates consistent handling of self-loops across all encoding methods.